#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QListView>
#include <QStandardItemModel>
#include <QStringList>
#include <QStandardItem>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_listView=new QListView(this);
    m_standardItemModel=new QStandardItemModel(this);
    QStringList strList;
    strList.append("string1");
    strList.append("string2");
    strList.append("string3");
    strList.append("string4");
    strList.append("string5");
    strList.append("string6");
    strList.append("string7");
    strList<<"string8";
    strList+="string9";
    int nCount=strList.size();
    for(int i=0;i<nCount;i++)
    {
        QString string=static_cast<QString>(strList.at(i));
        QStandardItem *item=new QStandardItem(string);
        if(i%2==1)
        {
            QLinearGradient linearGrad(QPointF(0,0),QPointF(200,200));
            linearGrad.setColorAt(0,Qt::white);
            linearGrad.setColorAt(1,Qt::gray);
            QBrush brush(linearGrad);
            item->setBackground(brush);
            item->setSizeHint(QSize(200,30));
        }
        else
        {
            item->setSizeHint(QSize(200,20));
            item->setEditable(false);
        }
        m_standardItemModel->appendRow(item);
    }
    m_listView->setModel(m_standardItemModel);
    m_listView->setFixedSize(200,300);
}

MainWindow::~MainWindow()
{
    delete ui;
}
